$(document).ready(function(){
	
	

	
	
		$("input[name='delete']").click(function()
	window.location.href="TransaccionNocheregalo.php?accion=transDeleteNocheregalo&id_nocheregalo="+$(this).attr('id'));
	
	
         $("#chk_all").click(function(){

                    var chks=$("input:checkbox[name^='selected']");

                    chks.attr("checked",$(this).is(":checked"))

                })

                $("input[name^='selected']").click(function(){

                    var todos=$("input:checkbox[name^='selected']")

                    var activos=$("input:checked[name^='selected']")

                    $("#chk_all").attr("checked",todos.length==activos.length)

                })
                
              $("#elimina").click(function(){  
              	
              	 url="TransaccionNocheregalo.php";
 id=$(this).attr("id")
 ids="";
 elementos=$("#Nocheregalo").children("tbody").children("tr").children("td").children("input:checkbox:checked");
elementos.each(function(i){ids?ids+=";"+$(this).attr("id"):ids=$(this).attr("id")});
  if(elementos.length==0 && (id=='elimina')) alert("Seleccione por lo menos un registro");
else            	
              	
 switch(id){
			 case 'elimina':ajax(url,"?accion=transDeleteNocheregalo&id_nocheregalo="+ids,elementos);
			 break;
			 
			 }
			 })
			 
			 
function ajax(url,vars,elementos_selec){
 $.ajax({type: "POST",url:url,data:vars,
 success: function(datos){
 res=(datos.split("_-_"));
 codigos=res[0].split("::")
 if(res[1]) alert(res[1]);
 if(elementos_selec.attr('id')=='icon_del' )
 codigos[0]=="-1"?elementos_selec.parent().parent().remove():"";
 else
 elementos_selec.each(function(i){
 if(!($(this).attr("id")==codigos[i]))
 $(this).parent().parent().remove();
 });
 }
 });
}
			 
		
	 $("#Nocheregalo").tableSorter({
 sortColumn: 'Habitaciones', // Integer or String of the name of the column to sort by.
 sortClassAsc: 'headerSortUp', // class name for ascending sorting action to header
 sortClassDesc: 'headerSortDown', // class name for descending sorting action to header
 headerClass: 'header', // class name for headers (th's)
 disableHeader: 'Ini/Fin' // DISABLE Sorting on <th>ID</th>
});		 
			 
			 
			 
			 //tabla editable
			 
			 
			 
$("input[name='edit']").click(function() {
     $('.tabladias').editable('http://localhost/objetos/TransaccionNocheregalo.php', {
         indicator : 'Saving...',
         tooltip   : 'Click to edit...'
     });
     $('.th_par').editable('http://localhost/objetos/TransaccionNocheregalo.php', { 
         type      : 'textarea',
         cancel    : 'Cancel',
         submit    : 'OK',
         indicator : '<img src="img/indicator.gif">',
         tooltip   : 'Click to edit...'
     });
 });


			 
			 
			 
			 
			 }); 